using System;
using System.Collections.Generic;
using System.Text;
using Entity;
using System.Data;
using System.Data.SqlClient;
using ECommerce.DAL;

namespace Entity
{
    [System.ComponentModel.DataObject]
    public class TblProductPurchaseOrderExtended : TblProductPurchaseOrder
    {

        public static ECommerce.DAL.CustomCollection<TblProductPurchaseOrder> GetBackendProductPurchaseOrderListByCondition(string condition, string sortBy, int firstItem, int pageSize)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();

            AddParameterToSqlCmd(sqlCmd, "@Condition", SqlDbType.NVarChar, 2000, ParameterDirection.Input, condition);
            AddParameterToSqlCmd(sqlCmd, "@Orderby", SqlDbType.NVarChar, 500, ParameterDirection.Input, sortBy);
            AddParameterToSqlCmd(sqlCmd, "@CurrentPageIndex", SqlDbType.Int, 0, ParameterDirection.Input, firstItem);
            AddParameterToSqlCmd(sqlCmd, "@PageSize", SqlDbType.Int, 0, ParameterDirection.Input, pageSize);

            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_PRODUCT_PURCHASE_ORDER_GET_LIST_BY_CONDITION);
            GenerateCollectionFromReader reader = new GenerateCollectionFromReader(GenerateTblProductPurchaseOrderCollectionFromReader);
            CustomCollection<TblProductPurchaseOrder> objCollection = ((CustomCollection<TblProductPurchaseOrder>)ExecuteReaderCmd(sqlCmd, reader));

            return objCollection;
        }

        public static int GetBackendProductPurchaseOrderListByConditionCount(string condition)
        {
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@Condition", SqlDbType.NVarChar, 2000, ParameterDirection.Input, condition);
            AddParameterToSqlCmd(sqlCmd, "@ReturnValue", SqlDbType.Int, 0, ParameterDirection.ReturnValue, null);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_PRODUCT_PURCHASE_ORDER_GET_LIST_BY_CONDITION_COUNT);
            ExecuteScalarCmd(sqlCmd);

            int returnValue = (int)sqlCmd.Parameters["@ReturnValue"].Value;
            return returnValue;
        }


        public static TblProductPurchaseOrder GetProductPurchaseOrderByOrderCode(string orderCode)
        {
            // Execute SQL Command
            SqlCommand sqlCmd = new SqlCommand();
            AddParameterToSqlCmd(sqlCmd, "@OrderCode", SqlDbType.NVarChar, 500, ParameterDirection.Input, orderCode);
            SetCommandType(sqlCmd, CommandType.StoredProcedure, SP_TBL_PRODUCT_PURCHASE_GET_ORDER_BY_ORDERCODE);
            GenerateCollectionFromReader reader = new GenerateCollectionFromReader(GenerateTblProductPurchaseOrderCollectionFromReader);
            CustomCollection<TblProductPurchaseOrder> objCollection = ((CustomCollection<TblProductPurchaseOrder>)ExecuteReaderCmd(sqlCmd, reader));

            if (objCollection.Count > 0)
                return objCollection[0];
            else
                return null;
        }

      


        private const string SP_TBL_PRODUCT_PURCHASE_ORDER_GET_LIST_BY_CONDITION = "sp_TblProductPurchaseOrder_Get_List_By_Condition";
        private const string SP_TBL_PRODUCT_PURCHASE_ORDER_GET_LIST_BY_CONDITION_COUNT = "sp_TblProductPurchaseOrder_Get_List_By_Condition_Count";
        private const string SP_TBL_PRODUCT_PURCHASE_GET_ORDER_BY_ORDERCODE = "sp_TblProductPurchaseOrder_Get_ProductPurchaseOrder_By_OrderCode";
     

    }
}
